﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using System.Data.SqlClient;
using System.Data.Odbc;
using System.Data.OleDb;


namespace CSharpDataAccess
{
    public enum QueryType
    {
        Query =1,
        StoreProcedure=2
    }

    public enum DataProvider
    {
        SQLServer = 1,
        OleDb = 2,
        Odbc = 4,
        Oracle = 8,
        MySQL = 16
    }

    class CSharpDataAccessHelper
    {
          public static IDbConnection GetConnection(DataProvider provider)
        {
            switch (provider)
            {
                case DataProvider.SQLServer:
                    return new SqlConnection();
                case DataProvider.OleDb:
                    return new OleDbConnection();
                case DataProvider.Odbc:
                    return new OdbcConnection();
                case DataProvider.Oracle:
                    return new OracleConnection();
                default:
                    return null;
            }
        }

          public static IDbCommand GetCommand(DataProvider provider)
        {
            switch (provider)
            {
                case DataProvider.SQLServer:
                    return new SqlCommand();
                case DataProvider.OleDb:
                    return new OleDbCommand();
                case DataProvider.Odbc:
                    return new OdbcCommand();
                case DataProvider.Oracle:
                    return new OracleCommand();
                default:
                    return null;
            }
        }

          public static IDbDataAdapter GetDataAdapter(DataProvider provider)
        {
            switch (provider)
            {
                case DataProvider.SQLServer:
                    return new SqlDataAdapter();
                case DataProvider.OleDb:
                    return new OleDbDataAdapter();
                case DataProvider.Odbc:
                    return new OdbcDataAdapter();
                case DataProvider.Oracle:
                    return new OracleDataAdapter();
                default:
                    return null;
            }
        }

          public static IDbTransaction GetTransaction(DataProvider provider)
        {
            IDbConnection iDbConnection = GetConnection(provider);
            IDbTransaction iDbTransaction = iDbConnection.BeginTransaction();
            return iDbTransaction;
        }

          public static IDataParameter GetParameter(DataProvider provider)
        {
            switch (provider)
            {
                case DataProvider.SQLServer:
                    return new SqlParameter();
                case DataProvider.OleDb:
                    return new OleDbParameter();
                case DataProvider.Odbc:
                    return new OdbcParameter();
                case DataProvider.Oracle:
                    return new OracleParameter();
                default:
                    return null;
            }
        }

          public static List<IDbDataParameter> GetParameters(DataProvider provider, int count)
        {
            return new List<IDbDataParameter>(count);
        }       
    }
}
